#include "MPEPanel.h"
#include "FileGrid.h"

MPEPanel::MPEPanel(wxWindow *parent)
        : wxPanel(parent, wxID_ANY)
{
  m_pBoxSizer = new wxBoxSizer(wxVERTICAL);
  m_pFlexGridSizer = new wxFlexGridSizer(MPE_GRID_ROWS, MPE_GRID_COLS, MPE_GRID_VGAP, MPE_GRID_HGAP);
  for(int col=0; col<MPE_GRID_COLS; col++)
  {
    m_pFlexGridSizer->AddGrowableCol(col);
  }
  for(int row=0; row<MPE_GRID_ROWS; row++){
    m_pFlexGridSizer->AddGrowableRow(row);
  }
  
  placeLabel(m_pScenarioLabel, wxT(SCENARIO_FILE));
  placeLabel(m_pDRLabel, wxT(DR_FILE));
  placeGrid(m_pScenarioGrid, wxT(SCENARIO_FILE));
  placeGrid(m_pDRGrid, wxT(DR_FILE));

  placeLabel(m_pSelectivityLabel, wxT(SELECTIVITY_FILE));
  placeLabel(m_pGearsLabel, wxT(GEARS_FILE));
  placeGrid(m_pSelectivityGrid, wxT(SELECTIVITY_FILE));
  placeGrid(m_pGearsGrid, wxT(GEARS_FILE));
 
  placeLabel(m_pHCRLabel, wxT(HCR_FILE));
  placeLabel(m_pAMLabel, wxT(AM_FILE));
  placeGrid(m_pHCRGrid, wxT(HCR_FILE));
  placeGrid(m_pAMGrid, wxT(AM_FILE));

  //m_pFlexGridSizer->Add(m_pPopulationSizePanel, wxSizerFlags().Expand().Border(wxALL,BORDER_SIZE));
  m_pBoxSizer->Add(m_pFlexGridSizer, wxSizerFlags().Expand().Border(wxALL,BORDER_SIZE));

  SetAutoLayout(true);
  SetSizerAndFit(m_pBoxSizer);
}

void MPEPanel::loadMPE(wxString filename)
{
  // Load all the grids with the MPE config files (CSVs)
  // Load master grid
  //loadFileIntoGrid(m_pMasterGrid, filename);
  // Load all the subgrids by iterating on MasterGrid

}

void MPEPanel::placeLabel(wxStaticText*& label, wxString text)
{
  label = new wxStaticText(this,
                           wxID_ANY,
                           text,
                           wxDefaultPosition,
                           wxDefaultSize,
                           wxALIGN_CENTER | wxEXPAND);
   m_pFlexGridSizer->Add(label,
                         1,
                         wxALIGN_CENTER | wxEXPAND);
}

void MPEPanel::placeGrid(wxGrid*& grid, wxString filename)
{
  if(filename){
    grid = new FileGrid(this, filename);
    m_pFlexGridSizer->Add(grid, 1, wxEXPAND);
  }
}

MPEPanel::~MPEPanel()
{
}

BEGIN_EVENT_TABLE ( MPEPanel, wxPanel )

END_EVENT_TABLE()
